#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

char s[1000100];
int next[1000100];
int n,slen;
void BuildNext()
{
    next[0]=-1;
    int i,j=0;
    FOR(i,1,slen)
    {
        while(j&&s[j]!=s[i]) j=next[j-1]+1;
        if(s[j]==s[i])
        {
            if((i+1)%(i-j)==0)
                printf("%d %d\n",i+1,(i+1)/(i-j));
            next[i]=j++;
        }
        else next[i]=j-1;
    }
    REP(i,slen) printf("next[%d]=%d ",i,next[i]+1);
    cout<<endl<<endl;
}
int main()
{
    int ca = 1;
    while(cin>>n)
    {
        if(!n) break;
        printf("Test case #%d\n",ca++);
        scanf("%s",s);
        slen = strlen(s);
        BuildNext();
      //  FOR(i,1,slen) if(next[i]!=-1&&(i+1)%(i-next[i])==0)
       //     printf("%d %d\n",i+1,(i+1)/(i-next[i]));
        cout<<endl;
    }
	return 0;
}
//10 abaababaab
